define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            $(".btn-add").data("area", ["100%", "100%"]);
            $(".btn-edit").data("area", ["100%", "100%"]);
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'staff/salary/index' + location.search,
                    add_url: 'staff/salary/add',
                    edit_url: 'staff/salary/edit',
                    del_url: 'staff/salary/del',
                    multi_url: 'staff/salary/multi',
                    import_url: 'staff/salary/import',
                    table: 'staff_salary',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'staff_id', title: __('Staff_id')},
                        {field: 'shop_id', title: __('Shop_id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'salaryyearmonth', title: __('Salaryyearmonth'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'basepay', title: __('Basepay'), operate: 'LIKE'},
                        {field: 'positionsalary', title: __('Positionsalary'), operate: 'LIKE'},
                        {field: 'meritpay', title: __('Meritpay'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'senioritysalary', title: __('Senioritysalary'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'othersubsidies', title: __('Othersubsidies'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'vacationsalary', title: __('Vacationsalary'), operate: 'LIKE'},
                        {field: 'overtimepay', title: __('Overtimepay'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'mealsupplements', title: __('Mealsupplements'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'heatingsubsidy', title: __('Heatingsubsidy'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'otherrewards', title: __('Otherrewards'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'unitvacation', title: __('Unitvacation'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'fixedsalary', title: __('Fixedsalary'), operate: 'LIKE'},
                        {field: 'totalsubsidy', title: __('Totalsubsidy'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'totalamount', title: __('Totalamount'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'netsalary', title: __('Netsalary'), operate: 'LIKE'},
                        {field: 'otherpayments', title: __('Otherpayments'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'otherdeductions', title: __('Otherdeductions'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'elderlycare', title: __('Elderlycare'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'medicalcare', title: __('Medicalcare'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'unemployment', title: __('Unemployment'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'accumulationfund', title: __('Accumulationfund'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'personalincometax', title: __('Personalincometax'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'servicecharge', title: __('Servicecharge'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'unitpayssocialsecurity', title: __('Unitpayssocialsecurity'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'unitpayshousingprovidentfund', title: __('Unitpayshousingprovidentfund'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {

            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
